﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Camc.Quality.Configuration;
using Camc.Quality.Web;

namespace Camc.Quality.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class QualityDbContextFactory : IDesignTimeDbContextFactory<QualityDbContext>
    {
        public QualityDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<QualityDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            QualityDbContextConfigurer.Configure(builder, configuration.GetConnectionString(QualityConsts.ConnectionStringName));

            return new QualityDbContext(builder.Options);
        }
    }
}